/*
 * @(#)ProjectTreeContentPorvidor.java.java        0.00 2007/12/24
 */
package jp.ekasi.pms.ui.grid.providor;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import jp.ekasi.pms.model.ModelPackage;
import jp.ekasi.pms.model.Project;
import jp.ekasi.pms.model.Task;

import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.edit.provider.ViewerNotification;

/**
 * @author sumari.rutao@gamil.com
 */
public class ProjectTreeContentPorvidor extends AbstractTreeContentsProvidor {
	
	public ProjectTreeContentPorvidor(AdapterFactory adapterFactory) {
		super(adapterFactory);
	}

	@Override
	public Collection<?> getChildren(Object object) {
		List<Task> result = new ArrayList<Task>();
		
		Project project = (Project)object;		
		List<Task> taskList = project.getTaskList();
		for (Task task : taskList) {
			if(task.getSummaryTask()==null) {
				result.add(task);
			}
		}
		
		return result;
	}
	
	@Override
	public void notifyChanged(Notification notification) {
		updateChildren(notification);

		switch (notification.getFeatureID(Project.class)) {
			case ModelPackage.PROJECT__UID:
			case ModelPackage.PROJECT__NAME:
			case ModelPackage.PROJECT__START:
			case ModelPackage.PROJECT__FINISH:
			case ModelPackage.PROJECT__DESCRIPTION:
				fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true));
				return;
			case ModelPackage.PROJECT__TASK_LIST:
			case ModelPackage.PROJECT__RESOURCES:
				fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), true, false));
				return;
		}
		super.notifyChanged(notification);
	}
}
